home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / LIBIP / PCCFCT2.C < prev    next >
C/C++ Source or Header  |  1999-09-11  |  3KB  |  163 lines

  1. /* 
  2.  * pccfct2.c
  3.  * 
  4.  * Practical Algorithms for Image Analysis
  5.  * 
  6.  * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
  7.  */
  8.  
  9. /* PCCFCT2:     functions for PCC: miscellaneous or common to encode/decode
  10.  *            (encoding functions in PCCFCT; decoding functions
  11.  *              in PCCFCTDE)
  12.  *      FUNCTIONS:
  13.  *              PCCBRANCH, NBRTOXY
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include "pcc2.h"               /* header file for PCC programs */
  19.  
  20. /* PCCBRANCH:   function adds new branch information
  21.  *                    usage: pccbranch (&branch, x, y, variable)
  22.  */
  23.  
  24. pccbranch (branch, x, y, variable)
  25.      struct branch1 **branch;   /* branch */
  26.      long x, y;                 /* location of branch */
  27.      long variable;             /* used for different things by
  28.                                  * * diff. fcts: dirn or type */
  29. {
  30.   long temp;
  31.  
  32.   (*branch)->x = x;
  33.   (*branch)->y = y;
  34.   (*branch)->variable = variable;
  35.   if (((*branch)->next = (struct branch1 *) malloc (sizeof (struct branch1)))
  36.       == NULL) {
  37.     printf ("PCCBRANCH: not enough memory -- sorry", 1);
  38.     return (-1);
  39.   }
  40.   temp = (long) *branch;
  41.   *branch = (*branch)->next;
  42.   (*branch)->previous = (struct branch1 *) temp;
  43.   return (0);
  44. }
  45.  
  46.  
  47.  
  48. /* NBRTOXY:     function converts 5x5 neighborhood position to
  49.  *            to x,y coordinates 
  50.  *                      usage: nbrtoxy (nbrhd, xCenter, yCenter, &x, &y)
  51.  *
  52.  */
  53.  
  54. nbrtoxy (nbrhd, xCenter, yCenter, x, y)
  55.      register long nbrhd,       /* neighborhood position number */
  56.        xCenter, yCenter;        /* coordinates of center point */
  57.      long *x, *y;               /* output coord.s of neighbor point */
  58. {
  59.   switch (nbrhd) {
  60.   case 0:
  61.     *x = xCenter;
  62.     *y = yCenter;
  63.     break;
  64.   case 1:
  65.     *x = xCenter;
  66.     *y = yCenter - 1;
  67.     break;
  68.   case 2:
  69.     *x = xCenter + 1;
  70.     *y = yCenter - 1;
  71.     break;
  72.   case 3:
  73.     *x = xCenter + 1;
  74.     *y = yCenter;
  75.     break;
  76.   case 4:
  77.     *x = xCenter + 1;
  78.     *y = yCenter + 1;
  79.     break;
  80.   case 5:
  81.     *x = xCenter;
  82.     *y = yCenter + 1;
  83.     break;
  84.   case 6:
  85.     *x = xCenter - 1;
  86.     *y = yCenter + 1;
  87.     break;
  88.   case 7:
  89.     *x = xCenter - 1;
  90.     *y = yCenter;
  91.     break;
  92.   case 8:
  93.     *x = xCenter - 1;
  94.     *y = yCenter - 1;
  95.     break;
  96.   case 9:
  97.     *x = xCenter;
  98.     *y = yCenter - 2;
  99.     break;
  100.   case 10:
  101.     *x = xCenter + 1;
  102.     *y = yCenter - 2;
  103.     break;
  104.   case 11:
  105.     *x = xCenter + 2;
  106.     *y = yCenter - 2;
  107.     break;
  108.   case 12:
  109.     *x = xCenter + 2;
  110.     *y = yCenter - 1;
  111.     break;
  112.   case 13:
  113.     *x = xCenter + 2;
  114.     *y = yCenter;
  115.     break;
  116.   case 14:
  117.     *x = xCenter + 2;
  118.     *y = yCenter + 1;
  119.     break;
  120.   case 15:
  121.     *x = xCenter + 2;
  122.     *y = yCenter + 2;
  123.     break;
  124.   case 16:
  125.     *x = xCenter + 1;
  126.     *y = yCenter + 2;
  127.     break;
  128.   case 17:
  129.     *x = xCenter;
  130.     *y = yCenter + 2;
  131.     break;
  132.   case 18:
  133.     *x = xCenter - 1;
  134.     *y = yCenter + 2;
  135.     break;
  136.   case 19:
  137.     *x = xCenter - 2;
  138.     *y = yCenter + 2;
  139.     break;
  140.   case 20:
  141.     *x = xCenter - 2;
  142.     *y = yCenter + 1;
  143.     break;
  144.   case 21:
  145.     *x = xCenter - 2;
  146.     *y = yCenter;
  147.     break;
  148.   case 22:
  149.     *x = xCenter - 2;
  150.     *y = yCenter - 1;
  151.     break;
  152.   case 23:
  153.     *x = xCenter - 2;
  154.     *y = yCenter - 2;
  155.     break;
  156.   case 24:
  157.     *x = xCenter - 1;
  158.     *y = yCenter - 2;
  159.     break;
  160.   }
  161.   return (0);
  162. }
  163.